package test6;

import java.io.*;

/**
 * @title: 这个问题用滑动窗口解决
 * @description:
 * @Author 易俊杰
 * @data: 2022/7/3 14:39
 * @version: V1.0
 */
public class Demo1 {
    public static void main(String[] args) throws IOException {
        System.out.println(StringCleaner("aaaa"));
    }

    //连续重复字符串
    public static String StringCleaner(String s) {
        StringBuilder str = new StringBuilder(s);
        int next = str.length() - 1, pre, flag;
        while (next > 1) {
            pre = next - 1;
            while (pre >= 0) {
                flag = pre;
                if (str.charAt(pre) == str.charAt(next)) {
                    pre--;
                }
                if (flag == pre) break;
            }
            if (next - pre > 1) {
                str = new StringBuilder(str.substring(0, pre + 1)).append(str.substring(next + 1));
                next = str.length();
            }
            next--;
        }
        return str.toString();
    }
}
